﻿#Region "IMPORTS"

Imports DAO

#End Region

Public Class FuncionarioDao
    Inherits DAO(Of Funcionario)


#Region "CONSTRUTOR(S)"

    Public Sub New()
        MyBase.New()
    End Sub

#End Region

#Region "METODOS ABSTRATOS"

    Protected Overrides Sub ValidarInsert(modelo As Funcionario)

        Dim NHQL As String = "from Funcionário where Cpf  = '" & modelo.Cpf & "'"
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe uma Funcionario com esse CPF")
        End If
    End Sub

    Protected Overrides Sub ValidarDelete(modelo As Funcionario)

    End Sub

    Protected Overrides Sub ValidarUpdate(ByVal modelo As Funcionario)

        Dim NHQL As String = "from Funcionário as f where f.Cpf  = '" & modelo.Cpf & "' AND f.FuncionarioId != " & modelo.FuncionarioId
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe uma Funcionario com esse CPF")
        End If

    End Sub

#End Region
End Class
